package edu.gatech.cs2340.spring2012.team38.database;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;


public class UserTable {

	public static final String TABLE_USERS = "users";
	public static final String COLUMN_ID = "_id";
	public static final String COLUMN_USERNAME = "username";
	public static final String COLUMN_PASSWORD = "password";
	public static final String COLUMN_GROUP = "group";

	// Database creation sql statement
	private static final String DATABASE_CREATE = "create table "
			+ TABLE_USERS + "( " + COLUMN_ID
			+ " integer primary key autoincrement, " + COLUMN_USERNAME
			+ " text not null" + COLUMN_PASSWORD + ");";
	
	/**
	 * Creates the User Database
	 * @param db The variable that will hold the database reference
	 */
	public static void onCreate(SQLiteDatabase db) {
		db.execSQL(DATABASE_CREATE);
	}
	
	/**
	 * This destroys the db and upgrades the db to a new version. We will
	 * almost certainly not use this, but it was needed for the helper class.
	 * @param db The version to upgrade
	 * @param oldVersion The old db version
	 * @param newVersion The new db version
	 */
	public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(UserTable.class.getName(), "Upgrading database from version "
				+ oldVersion + " to " + newVersion
				+ ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
		onCreate(db);
	}

}
